package com.htht.smartschool.service.maintain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.htht.smartschool.common.service.BaseService;
import com.htht.smartschool.model.maintain.MaintainPie;

public class MaintainService extends BaseService {
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map getBarChart(){
		Map map = new HashMap();
		String arr = "";
		try {
			String sql = "select id from t_student";
			List<Object[]> list = getDao().queryBySQL(sql);
			if(list!=null&&list.size()>0){
				arr = list.size()+"";
			}
			
			sql = "select id from t_card";
			list = getDao().queryBySQL(sql);
			if(list!=null&&list.size()>0){
				arr = arr +","+list.size();
			}
			map.put("data", arr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map getUserChart(){
		Map map = new HashMap();
		MaintainPie pie = null;
		List<MaintainPie> lists = new ArrayList<MaintainPie>();
		try {
			String sql = "SELECT COUNT(1),usertype FROM t_user GROUP BY usertype";
			List<Object[]> list = getDao().queryBySQL(sql);
			if(list!=null&&list.size()>0){
				for(Object[] obj : list){
					pie = new MaintainPie();
					pie.setName(parString(String.valueOf(obj[1])));
					pie.setValue(Integer.parseInt(String.valueOf(obj[0])));
					if(!String.valueOf(obj[1]).equals("3")){
						lists.add(pie);
					}
				}
			}
			map.put("data", lists);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map getSchoolChart(){
		Map map = new HashMap();
		try {
			String arr = "";
			String sql = "select id from t_teacher";
			List<Object[]> list = getDao().queryBySQL(sql);
			if(list!=null&&list.size()>0){
				arr = list.size()+"";
			}
			
			sql = "select id from t_student";
			list = getDao().queryBySQL(sql);
			List<MaintainPie> lists = new ArrayList<MaintainPie>();
			if(list!=null&&list.size()>0){
				arr = arr +","+list.size();
			}
			map.put("data", arr);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	public Integer getSchoolCount(){
		String sql = "select count(*) from t_school";
		int schoolCount = getDao().getCountBySqlPage(sql);
		return schoolCount;
	}
	public String parString(String typeId){
		String name = "";
		if(typeId.equals("0")){
			name = "管理";
		}else if(typeId.equals("1")){
			name = "家长";
		}else if(typeId.equals("2")){
			name = "教师";
		}
		return name;
	}
}
